using System;
using System.Web;
using System.Xml;

using umlungu.engineX;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2007-MM-DD	
	Status:		release	
	Version:	2.0.0
	Build:		20071104
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20071104:	Started
	-----------------------------------------------------------------------	*/

namespace umlungu.engineX.blogX {
	/// <summary>
	/// Description of the uploaderX class.
	/// <para>Additional information about the class</para>
	/// </summary>
	public class uploaderX : System.Web.UI.Page {
		#region Invisible properties
		private x_logger logger;
		#endregion

		#region Constants
		private const string THIS_CONST = "A constant";
		#endregion

		#region Visible properties
		private string property;
		/// <summary>Definiton of the property</summary>
		/// <value>Description of the value of the property</value>
		public string Property {
			get { return property; }
			set { property = value; }
		}
		private x_config config;
		/// <summary>Configuration object</summary>
		/// <value>Configuration values acces via the object</value>
		public x_config Config {
			get { return config; }
		}
		/// <summary>Unique file identifier</summary>
		/// <value>File GUID</value>
		public string FileID {
			get {
				Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
				Byte[] b = new Byte[16];
				rdm.NextBytes(b);
				Guid thisguid = new Guid(b);
				return thisguid.ToString();
			}
		}
		#endregion

		#region Constructors/Destructors
		/// <summary>Default constructor</summary>
		public uploaderX() : base() {
			logger = new x_logger(typeof(uploaderX));
			config = new x_config();
		}
		#endregion

		#region Public methods
		/// <summary>Does the uploading from a form submission</summary>
		public void Upload() {
			string thisID = Request.Form["FileID"];
			logger.Info(String.Concat("Upload:", Request.Files.Count.ToString()));
			try {
				if (Request.Files.Count > 0) {
					HttpPostedFile thisfile = Request.Files.Get(0);
					int last = thisfile.FileName.LastIndexOf(".");
					string filename = Server.MapPath(String.Concat("data/", thisID, thisfile.FileName.Substring(last)));
					thisfile.SaveAs(filename);
				}
			} catch {
			}
			//Response.Write(thisID);
			Response.Write("<HTML><HEAD><TITLE></TITLE></HEAD><body onload='javascript:window.close();'></body></HTML>");
		}
		/// <summary>Gets</summary>
		public void GetFileID() {
			Response.Write(FileID);
		}
		#endregion

		#region Protected methods
		#endregion

		#region Private methods
		#endregion
	}
}